<!--
 * @Author: 2112778581 2112778581@qq.com
 * @Date: 2024-01-17 15:17:08
 * @LastEditors: 2112778581 2112778581@qq.com
 * @LastEditTime: 2024-01-17 15:17:16
 * @FilePath: \my-sjksh\three\01-三角形.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Three.js Triangle</title>
  <style>
    body { margin: 0; }
    canvas { display: block; }
  </style>
</head>
<body>
  <script type="module">
    import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r125/build/three.module.js';
    import { OriControl } from 'https://threejsfundamentals.org/threejs/resources/threejs/r125/build/three.module.js'
    // 创建场景
    const scene = new THREE.Scene();


    const geometry = new THREE.PlaneGeometry(5,2);    

    // 创建材质
    const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });

    // 创建网格对象
    const triangle = new THREE.Mesh(geometry, material);
    // triangle.rotateX(-Math.PI / 2)
    // 将三角形添加到场景
    scene.add(triangle);

    const axes = new THREE.AxesHelper(5);

    scene.add(axes)

    // 创建相机
    const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
    camera.position.z = 5;

    // 创建渲染器
    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    // 渲染循环
    function animate() {
      requestAnimationFrame(animate);
      renderer.render(scene, camera);
    }

    // 监听窗口大小变化
    window.addEventListener('resize', () => {
      const newWidth = window.innerWidth;
      const newHeight = window.innerHeight;
      camera.aspect = newWidth / newHeight;
      camera.updateProjectionMatrix();
      renderer.setSize(newWidth, newHeight);
    });

    // 启动渲染循环
    animate();
  </script>
</body>
</html>
